﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using EntityFrameworks.Data.Core;
using EntityFrameworks.Entity.Core;
using EntityFrameworks.Entity.Core.CommonEnums;
using EntityFrameworks.Entity.Core.Specification;
namespace Common.Background.BLL
{
    public class DeptManager : BLLBase
    {
        public DeptManager()
            : base(new backgroundEntities())
        {

        }
        public PagedList<WebDepartments> GetDept(DeptSpecification deptSpecification, PageParameters pp)
        {
            var linq = from data1 in LoadRepository<WebDepartments>().GetModel(deptSpecification)
                                                                     .Include(i => i.WebDepartments2)
                       join data2 in LoadRepository<WebManageUsers>().GetModel()
                       on data1.DepartmentID equals data2.DepartmentID into list
                       where data1.Status != (int)Status.Deleted
                       select new WebDepartments_Ext
                       {
                           DepartmentID = data1.DepartmentID,
                           DepartmentName = data1.DepartmentName,
                           ParentID = data1.ParentID,
                           SortNumber = data1.SortNumber,
                           Status = data1.Status,
                           UserCount = list.Count(),
                           DeptLevel = data1.DeptLevel,
                           WebDepartments2 = data1.WebDepartments2
                       };

            return linq.OrderBy(i => i.DepartmentID)
                .ToPagedList<WebDepartments>(pp.PageIndex, pp.PageSize);
        }

    }
}